public abstract class AbstractListenerWriteProcessor<T>
extends java.lang.Object
Processor
implementations that bridge between
event-listener write APIs and Reactive Streams.
Specifically a base class for writing to the HTTP response body with Servlet 3.1 non-blocking I/O and Undertow XNIO as well for writing WebSocket messages through the Java WebSocket API (JSR-356), Jetty, and Undertow.
Modifier and Type | Class and Description |
---|---|
private static class |
AbstractListenerWriteProcessor.State
Represents a state for the
Subscriber to be in. |
Modifier and Type | Field and Description |
---|---|
protected T |
currentData |
protected Log |
logger |
private WriteResultPublisher |
resultPublisher |
private java.util.concurrent.atomic.AtomicReference<AbstractListenerWriteProcessor.State> |
state |
private boolean |
subscriberCompleted |
private Subscription |
subscription |
Constructor and Description |
---|
AbstractListenerWriteProcessor() |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Listeners can call this method to cancel further writing.
|
private boolean |
changeState(AbstractListenerWriteProcessor.State oldState,
AbstractListenerWriteProcessor.State newState) |
protected abstract boolean |
isDataEmpty(T data)
Whether the given data item contains any actual data to be processed.
|
protected abstract boolean |
isWritePossible()
Whether writing is possible.
|
void |
onComplete() |
void |
onError(java.lang.Throwable t) |
void |
onNext(T data) |
void |
onSubscribe(Subscription subscription) |
void |
onWritePossible()
Listeners can call this to notify when writing is possible.
|
protected void |
receiveData(T data)
Called when a data item is received via
Subscriber#onNext(Object) |
protected abstract void |
releaseData()
Called when the current received data item can be released.
|
void |
subscribe(<any> subscriber) |
protected void |
suspendWriting()
Suspend writing.
|
protected abstract boolean |
write(T data)
Writes the given data to the output.
|
private void |
writeIfPossible() |
protected void |
writingComplete()
Invoked when writing is complete.
|
protected void |
writingFailed(java.lang.Throwable ex)
Invoked when an error happens while writing.
|
protected final Log logger
private final WriteResultPublisher resultPublisher
private final java.util.concurrent.atomic.AtomicReference<AbstractListenerWriteProcessor.State> state
private volatile boolean subscriberCompleted
@Nullable private Subscription subscription
public final void onSubscribe(Subscription subscription)
public final void onNext(T data)
public final void onError(java.lang.Throwable t)
public final void onComplete()
public final void subscribe(<any> subscriber)
public final void onWritePossible()
public void cancel()
protected void receiveData(T data)
Subscriber#onNext(Object)
protected abstract void releaseData()
protected abstract boolean isDataEmpty(T data)
protected abstract boolean isWritePossible()
protected abstract boolean write(T data) throws java.io.IOException
data
- the data to writetrue
)
and new data can be requested, or otherwise (false
)java.io.IOException
protected void suspendWriting()
protected void writingComplete()
protected void writingFailed(java.lang.Throwable ex)
Defaults to no-op. Servlet 3.1 based implementations will receive
javax.servlet.WriteListener#onError(Throwable)
event.
private boolean changeState(AbstractListenerWriteProcessor.State oldState, AbstractListenerWriteProcessor.State newState)
private void writeIfPossible()